package desktopSearch;

import org.mira.lucene.analysis.*;
import org.apache.lucene.analysis.*;
import java.io.*;

public class AnalyzerTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length < 1)
		{
			return;
		}
		AnalyzerTest at = new AnalyzerTest();
		String path = args[0];
		try
		{
			System.out.println("Test IK_CAnalyzer=================>");
			Analyzer analyzer = new IK_CAnalyzer();
			at.testAnalyzer(path, analyzer);
			
			System.out.println("Test MIK_CAnalzyer================>");
			at.testAnalyzer(path, new MIK_CAnalyzer());
			
		}
		catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
	}

	private void testAnalyzer(String path, Analyzer analyzer)
		throws FileNotFoundException, IOException
	{
		//Analyzer analyzer = new IK_CAnalyzer();
		Reader r = new FileReader(path);
		TokenStream ts = (TokenStream)analyzer.tokenStream("", r);
		printTokenStream(ts);
		
	}

	private void printTokenStream(TokenStream ts) throws IOException {
		Token t;
		int len = 0;
		while((t = ts.next()) != null)
		{
			String str = t.termText();
			System.out.print(str + " ");
			len += str.length();
			if (len > 32)
			{
				System.out.println();
				len = 0;
			}
		}
		System.out.println();
	}

}
